package org.misty.redis.autoconfigure.client;

import lombok.extern.slf4j.Slf4j;
import org.misty.redis.client.JedisPoolAdapter;
import org.misty.redis.client.RedisClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

/**
 * @author Misty on 2020-06-10
 */
@Slf4j
@Configuration
@ConditionalOnClass({JedisPool.class})
@ConditionalOnExpression("${redis-tools.client.default.enabled:true}")
@ConditionalOnMissingClass("org.springframework.data.redis.core.StringRedisTemplate")
@ConditionalOnMissingBean({RedisClient.class})
public class JedisPoolConfiguration {
    @Bean
    public RedisClient redisClient(JedisPool jedisPool) {
        return new JedisPoolAdapter(jedisPool);
    }
}
